<?php

namespace Analysis\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function index()
    {
        $this->display();
    }
    
    public function login()
    {
        $manager=M("groupuser");
        
        $post=I("post.");
        $where=array(
            "gro_name"=>$post['user'],
            "gro_pass"=>$this->passEncode($post['pass']),
            'gro_status'=>1
        );
        $info=$manager->where($where)->find();
        if ($info['gro_name']!=null) {
            session("dataAnalsys", $info['gro_id']);
            $this->redirect("Dash/index");
        } else {
            $this->error("用户名或密码错误");
        }
    }
    
    public function out()
    {
        session("dataAnalsys", null);
        if (session("dataAnalsys")==null) {
            $this->redirect("Index/index");
        } else {
            session_destroy();
            $this->redirect("Index/index");
        }
    }
    
    private function passEncode($str)
    {
        $pa = substr(md5(trim($str)), 12, 32);
        return $pa;
    }
}
